package com.itheima.autoCode.service.strategy;

import com.itheima.autoCode.dto.CodeContext;
import com.itheima.autoCode.service.strategy.code.*;
import com.itheima.w_dto.DependencieInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

@Slf4j
@Service
public class CodeStyleDDDStrxategy extends AbstrctractCodeStyleStrategy {

    private static final String[] MODULES = {"api", "interfaces", "server", "domain", "infrastructure"};


    @Override
    protected void initCodeGeneraters() {
        registerCodeGenerater("api", new CodeGenerater_API_DDD());
        registerCodeGenerater("interfaces", new CodeGenerater_INTERFACE_DDD());
        registerCodeGenerater("server", new CodeGenerater_SERVER_DDD());
        registerCodeGenerater("domain", new CodeGenerater_DOMAIN_DDD());
        registerCodeGenerater("infrastructure", new CodeGenerater_INFRASTRUCTURE_DDD());
    }

    @Override
    protected void createSomeCode(CodeContext codeContext, String item) {
        CodeGenerater generaters = getCodeGeneraters(item);
        codeContext.getProcessParams().setCodeGeneraters(this.codeGeneraters);
        generaters.initCode(codeContext);
    }

    @Override
    protected Map<String, List<String>> getdenpyOfMoudles() {
        return new HashMap<String, List<String>>() {{
            put("interfaces", Arrays.asList("server"));
            put("server", Arrays.asList("domain"));
            put("domain", Arrays.asList("infrastructure"));
            put("api", Arrays.asList());
            put("infrastructure", Arrays.asList());
        }};
    }

    @Override
    protected Map<String, List<DependencieInfo>> getDenpyOfWeb(CodeContext codeContext) {
        return new HashMap<String, List<DependencieInfo>>() {{
            put(codeContext.getArtifactId(), new ArrayList<DependencieInfo>() {{
                add(DependencieInfo.builder()
                        .artifactId("fastjson")
                        .groupId("com.alibaba")
                        .version("1.2.47")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("hutool-all")
                        .groupId("cn.hutool")
                        .version("5.8.10")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("lombok")
                        .groupId("org.projectlombok")
                        .version("1.18.20")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("spring-boot-configuration-processor")
                        .groupId("org.springframework.boot")
                        .optional("true")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("slf4j-api")
                        .groupId("org.slf4j")
                        .version("1.7.10")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("log4j-slf4j-impl")
                        .groupId("org.apache.logging.log4j")
                        .version("2.20.0")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("log4j-api")
                        .groupId("org.apache.logging.log4j")
                        .version("2.20.0")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("log4j-core")
                        .groupId("org.apache.logging.log4j")
                        .version("2.20.0")
                        .build());
            }});
            put("api", new ArrayList<DependencieInfo>() {{
            }});
            put("interfaces", new ArrayList<DependencieInfo>() {{
                add(DependencieInfo.builder()
                        .artifactId("spring-boot-starter-web")
                        .groupId("org.springframework.boot")
                        .exclusions(new ArrayList<DependencieInfo.ExclusionDTO>(){{
                            add(DependencieInfo.ExclusionDTO.builder()
                                    .artifactId("log4j-to-slf4j")
                                    .groupId("org.apache.logging.log4j")
                                    .build());
                            add(DependencieInfo.ExclusionDTO.builder()
                                    .artifactId("spring-boot-starter-logging")
                                    .groupId("org.springframework.boot")
                                    .build());
                        }})
                        .build());
            }});
            put("server", new ArrayList<DependencieInfo>() {{
            }});
            put("domain", new ArrayList<DependencieInfo>() {{
            }});
            put("api", new ArrayList<DependencieInfo>() {{
            }});
            put("infrastructure", new ArrayList<DependencieInfo>() {{
                add(DependencieInfo.builder()
                        .artifactId("mysql-connector-java")
                        .groupId("mysql")
                        .version("5.1.35")
                        .desc("MySQL数据库驱动")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("mybatis-plus-boot-starter")
                        .groupId("com.baomidou")
                        .version("3.4.1")
                        .desc("mybatis-plus简化开发")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("mapstruct")
                        .groupId("org.mapstruct")
                        .version("1.4.2.Final")
                        .desc("mapstruct简化实体映射")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("mapstruct-processor")
                        .groupId("org.mapstruct")
                        .version("1.4.2.Final")
                        .desc("mapstruct简化实体映射")
                        .build());
                add(DependencieInfo.builder()
                        .artifactId("lombok-mapstruct-binding")
                        .groupId("org.projectlombok")
                        .version("0.2.0")
                        .desc("mapstruct简化实体映射-支持lombok")
                        .build());
            }});
        }};
    }


    @Override
    protected String[] getMoudles() {
        return MODULES;
    }

    @Override
    public CodeStyleEnums getIdentity() {
        return CodeStyleEnums.DDD;
    }


}
